package com.example.uchain.mapper;

import com.example.uchain.demo.WorksInformation;
import com.example.uchain.demo.dto.WorksInformationCountDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WorksInformationMapper {

    //查询
    @Select("select * from works_information")
    List<WorksInformation> findAll();

    @Select("select * from works_information where w_id = #{wid}")
    WorksInformation findAllById(@Param("wid") Long wid);

    //添加
    @Insert("insert into works_information (works_name,works_property,create_time,introduce,create_address,publish_state,firstpublish_time,publish_address,w_id,member_id)" +
            " values(#{worksName},#{worksProperty},#{createTime},#{introduce},#{createAddress},#{publishState},#{firstpublishTime},#{publishAddress},#{wid},#{memberId})")
    void AddInformation(WorksInformation worksInformation);

    //删除
    @Delete("delete from works_information where w_id = #{wid}")
    void deleteInformationById(Long wid);

    //根据id然后修改商品信息
    void updateById(WorksInformation worksInformation);

    //带条件的分页查询
    List<WorksInformation> findAll1(@Param("worksName") String worksName,
                                    @Param("worksProperty")String worksProperty,
                                    @Param("publishAddress")String publishAddress,
                                    @Param("publishState") String publishState,
                                    @Param("createAddress")String createAddress,
                                    @Param("wid")Long wid,
                                    @Param("code")Integer code);

    @Select("SELECT "
            + "SUM(CASE WHEN works_property = '原创' THEN 1 ELSE 0 END) AS totalWorksCount1, "
            + "SUM(CASE WHEN works_property = '改编' THEN 1 ELSE 0 END) AS totalWorksCount2, "
            + "SUM(CASE WHEN works_property = '其他' THEN 1 ELSE 0 END) AS totalWorksCount3, "
            + "SUM(CASE WHEN publish_state = '已发表' THEN 1 ELSE 0 END) AS totalWorksCount4, "
            + "SUM(CASE WHEN publish_state = '未发表' THEN 1 ELSE 0 END) AS totalWorksCount5 "
            + "FROM works_information")
    WorksInformationCountDTO WorksInformationCount();
}
